package src.edu.wayne.cs.csc4110.hw6.implementations.stateMachine;

import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class StateMachineFrame extends JFrame {
	private static final long serialVersionUID = 7518210752005123891L;
	
	private static StateMachineFrame stateMachineFrame;

	private JPanel currentPanel;
	private boolean boolPanelSet = false;
	private static final Color frameColor = new Color(59,89,152);
	
	private StateMachineFrame(){}

	public static synchronized StateMachineFrame getStateMachineFrame() {
		
		if (stateMachineFrame == null)
		{
			stateMachineFrame = new StateMachineFrame();
			stateMachineFrame.setSize(600,480);
			stateMachineFrame.setBackground(StateMachineFrame.frameColor);
			stateMachineFrame.setLocationRelativeTo(null); // Center the frame
			stateMachineFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			stateMachineFrame.setVisible(false);
		}
		return stateMachineFrame;
	}

	public void setCurrentPanel(JPanel newPanel, String newTitle)
	{
		if (boolPanelSet == true)
		{
			stateMachineFrame.setVisible(false);
			stateMachineFrame.remove(currentPanel);
			boolPanelSet = false;
		}
		boolPanelSet = true;
		currentPanel = newPanel;
		stateMachineFrame.add(newPanel);
		stateMachineFrame.setTitle(newTitle);
		stateMachineFrame.validate();
		stateMachineFrame.setVisible(true);
		stateMachineFrame.setResizable(false);
		stateMachineFrame.repaint();
	}
	
	public static Color getColor()
	{
		return StateMachineFrame.frameColor;
	}
	
}
